import { Drawer, Tabs } from 'antd';
import React, { useEffect, useState } from 'react';
import type { TabsProps } from 'antd';
import FrontEntity from '../components/fontEntity'
import BackEndEntity from './backEndEntity';
import CommonGenerate from './CommonGenerate';
import TableIndexGenerate from './tableIndexGenerate';

interface Props {
  isOpen: boolean,
  closeEvent: (isOpen: boolean) => void;
  TableInfo: Generator.TableInfo;
}

const GeneratorDrawer: React.FC<Props> = (props) => {
  const { isOpen, closeEvent, TableInfo } = props;
  const [open, setOpen] = useState(isOpen);
  const items: TabsProps['items'] = [
    {
      key: '4',
      label: '前端实体类',
      children: <FrontEntity TableInfo={TableInfo} />,
    },
    {
      key: '5',
      label: '前端服务层',
      children: <CommonGenerate IsFrontCode={true} GenerateType="FrontService" LabelTitle='服务层名称' Title='前端服务层' TemplateFileName='Service.tpl' TableInfo={TableInfo} />,
    },
    {
      key: '2',
      label: '前端列表页',
      children: <TableIndexGenerate TableInfo={TableInfo} />,
    },
    {
      key: '3',
      label: '后端实体类',
      children: <BackEndEntity TableInfo={TableInfo} />,
    },
    {
      key: '6',
      label: '后端控制器',
      children: <CommonGenerate GenerateType="Controller" LabelTitle='控制器名称' Title='后端控制器' TemplateFileName='Controller.tpl' TableInfo={TableInfo} />
    },
    {
      key: '7',
      label: '后端服务层',
      children: <CommonGenerate GenerateType="Service" LabelTitle='服务层名称' Title='后端服务层' TemplateFileName='Service.tpl' TableInfo={TableInfo} />
    },
    {
      key: '8',
      label: '后端服务接口层',
      children: <CommonGenerate GenerateType="IService" LabelTitle='服务层接口名称' Title='后端服务接口层' TemplateFileName='IService.tpl' TableInfo={TableInfo} />
    },
    {
      key: '9',
      label: '后端仓储层',
      children: <CommonGenerate GenerateType="Repository" LabelTitle='仓储层名称' Title='后端仓储层' TemplateFileName='Repository.tpl' TableInfo={TableInfo} />
    },
    {
      key: '10',
      label: '后端仓储接口层',
      children: <CommonGenerate GenerateType="IRepository" LabelTitle='仓储层接口名称' Title='后端仓储接口层' TemplateFileName='IRepository.tpl' TableInfo={TableInfo} />
    },
  ];

  const onClose = () => {
    setOpen(false);
    closeEvent(false)
  };

  useEffect(() => {
    setOpen(isOpen);
  }, [isOpen]);

  const onChange = (key: string) => {
    console.log(key);
  };

  return (
    <Drawer
      title={`代码生成配置`}
      width={
        1000}
      onClose={onClose}
      open={open}
      placement='right'
    >
      <Tabs defaultActiveKey="1" items={items} onChange={onChange} />
    </Drawer>
  );
}

export default GeneratorDrawer;
